package com.woniuxy.project115.kaer.commons.util;

import lombok.Data;

import java.util.Collections;
import java.util.List;

@Data
public class Result<T> {
    private Integer code;
    private String msg;
    private T data;
    private List<T> list;
    public Result() {
    }

    public Result(Integer code, String msg, T data,List<T> list) {
        this.code = code;
        this.msg = msg;
        this.data = data;
        this.list = list;
    }
    // 成功返回，包含消息、数据和列表
    public static <T> Result<T> succeed(String msg, T data, List<T> list) {
        return new Result<>(200, msg, data, list);
    }

    // 成功返回，只包含消息和数据
    public static <T> Result<T> succeed(String msg, T data) {
        return new Result<>(200, msg, data, Collections.emptyList());
    }

    // 成功返回，只包含消息
    public static <T> Result<T> succeed(String msg) {
        return new Result<>(200, msg, null, Collections.emptyList());
    }

    // 成功返回，使用默认消息
    public static <T> Result<T> succeed() {
        return new Result<>(200, "请求成功", null, Collections.emptyList());
    }

    // 失败返回，包含消息、数据和列表
    public static <T> Result<T> failed(String msg, T data, List<T> list) {
        return new Result<>(500, msg, data, list);
    }

    // 失败返回，只包含消息和数据
    public static <T> Result<T> failed(String msg, T data) {
        return new Result<>(500, msg, data, Collections.emptyList());
    }

    // 失败返回，只包含消息
    public static <T> Result<T> failed(String msg) {
        return new Result<>(500, msg, null, Collections.emptyList());
    }

    // 失败返回，使用默认消息
    public static <T> Result<T> failed() {
        return new Result<>(500, "请求失败", null, Collections.emptyList());
    }


}
